import { Component, OnInit, Output, EventEmitter } from '@angular/core';

@Component({
  selector: 'app-count',
  templateUrl: './count.component.html',
  styleUrls: ['./count.component.less'],
})
export class CountComponent implements OnInit {
  @Output() sub = new EventEmitter();
  @Output() add = new EventEmitter();
  @Output() statistics = new EventEmitter();
  count: number = 1;
  constructor() {}

  ngOnInit() {}
  handleAdd() {
    if (this.count <= 0) return;
    this.add.emit(++this.count);
    this.handleStatistics();
  }
  handleSub() {
    if (this.count <= 1) return;
    this.add.emit(--this.count);
    this.handleStatistics();
  }
  handleStatistics() {
    this.statistics.emit(this.count);
  }
  handleInitialization() {
    this.count = 1;
  }
}
